home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / statbox.exe / STATBOX.PAS < prev    next >
Pascal/Delphi Source File  |  1993-03-21  |  11KB  |  218 lines

  1. Unit StatBox;
  2.  
  3. {=========================================================================}
  4. { This Unit was written by Patrick Mitchel, March 1993 and donated to the }
  5. { public domain.                                                          }
  6. { It provides the user with an updating dialog box which can be used      }
  7. { to give the user feedback on the progress of some procedure.  I use it  }
  8. { for reporting the record number being processed in a database           }
  9. { application I wrote for my work.  The users like the visual feedback it }
  10. { gives instead of the static "PROCESSING" message that I used to display.}
  11. {                                                                         }
  12. { Many thanks to Steve Schafer for the initial code and idea for this     }
  13. { unit. I was looking for something exactly like this Steve!!  I just     }
  14. { took the code and put it into a Unit for reuse at any time.             }
  15. { Steve's original code can be found on compuserve as STATUS.PAS.         }
  16. {                                                                         }
  17. { The TStatusDialog box is dynamically sized in the X direction based     }
  18. { upon the length of the largest message you wish to display.  It is      }
  19. { also automatically centered in the parent view, and has a built in      }
  20. { value of R.B.Y - R.A.Y of 6.  This can be changed in this Unit, but     }
  21. { check out the demo first, I think you will find it satisfactory.        }
  22. {                                                                         }
  23. { If you find any bugs, or make some improvements, please let me know!    }
  24. { My Compuserve ID is 72400,2215.  This code has been very useful to me   }
  25. { and any improvements would only make my job easier!  Thanks!            }
  26. {*************************************************************************}
  27. {Using The Methods:                                                       }
  28. {                                                                         }
  29. {     Constructor Init (MyTitle : String;                                 }
  30. {                       Main1,Proc1,Done1,Cancel,Help : String);          }
  31. {     (********************************************************)          }
  32. {     (*Initializes the TStatusDialog box with the strings to *)          }
  33. {     (*display.  See the demo code to understand more fully  *)          }
  34. {     (*where/when each string is displayed, but below is a   *)          }
  35. {     (*brief explanation of where/when the strings are       *)          }
  36. {     (*displayed.                                            *)          }
  37. {     (*MyTitle : The title you wish displayed in the dialog  *)          }
  38. {     (*Main1   : The text related to the actual processing   *)          }
  39. {     (*          This text is always displayed during use    *)          }
  40. {     (*Proc1   : The text displayed beneath Main1 during     *)          }
  41. {     (*          processing                                  *)          }
  42. {     (*Done1   : The text displayed when processing is done  *)          }
  43. {     (*          Overwrites Proc1                            *)          }
  44. {     (*Cancel  : The test displayed when you cancel out of   *)          }
  45. {     (*          the process in the middle, like with ^C     *)          }
  46. {     (*          You will need to program in the ability to  *)          }
  47. {     (*          break into the process.  See the demo       *)          }
  48. {     (*Help    : The text displayed at the very bottom of the*)          }
  49. {     (*          dialog when processing is finished, can     *)          }
  50. {     (*          be used to give the user a hint on what to  *)          }
  51. {     (*          do next.                                    *)          }
  52. {     (********************************************************)          }
  53. {                                                                         }
  54. {     Procedure Update(Status : Word; AValue : Word); virtual;            }
  55. {     (********************************************************)          }
  56. {     (*Pass it the status, either cmValid, cmOk or cmCancel  *)          }
  57. {     (*depending on the status of your dialog box, along with*)          }
  58. {     (*AValue: the value to update the dialog box with.      *)          }
  59. {     (*Check out the sample program to really see how this   *)          }
  60. {     (*method is utilized.                                   *)          }
  61. {     (********************************************************)          }
  62. {                                                                         }
  63. {=========================================================================}
  64.  
  65. {$F+}          {Force Far Calls}
  66. {$O+}          {Enable Overlay Code Generation}
  67. {$S-}          {Disable Stack Overflow Checking Code}
  68. {$D-}          {Disable Debug Information}
  69.  
  70. Interface
  71.  
  72. Uses
  73.      Objects, Views, Dialogs;
  74.  
  75.  
  76. Type
  77.     {Updating Status Box Dialog}
  78.     PStatusDialog = ^TStatusDialog;
  79.     TStatusDialog = object(TDialog)
  80.                   MainMessage : string;         {displayed all the time}
  81.                   ProcMessage : string;         {in process message}
  82.                   DoneMessage : string;         {done message}
  83.                   CancelMessage : string;       {cancel message}
  84.                   HelpMessage   : string;       {help message}
  85.                   Message1    : PStaticText;    {holder for displaying msgs}
  86.                   Message2    : PStaticText;    {holder for displaying msgs}
  87.                   Message3    : PStaticText;    {holder for displaying msgs}
  88.                   Value       : PStaticText;    {value we are updating}
  89.                   Constructor Init(MyTitle : String;
  90.                                    Main1,Proc1,Done1,Cancel,Help : String);
  91.                   Procedure Update(Status : Word; AValue : Word); virtual;
  92.     End; {Status Dialog Object}
  93.  
  94. {=========================================================================}
  95. {=========================================================================}
  96.  
  97. Implementation
  98.  
  99.  
  100. Constructor TStatusDialog.Init(MyTitle : String;
  101.                                Main1,Proc1,Done1,Cancel,Help : String);
  102. Var
  103.    R      : TRect;   {bounds for string displays}
  104.    MaxLen : Integer; {holds max length of string}
  105.    Bounds : TRect;   {bounds for main dialog window}
  106. Begin
  107.      {calculate size of dialog based on largest message length}
  108.      {set initial X size of dialog, based on the dialogs title}
  109.      MaxLen := Length(MyTitle) + 6;
  110.      If (Length(Main1) + 5) > MaxLen Then
  111.         MaxLen := Length(Main1) + 5;    {to allow for 4 place value}
  112.      If Length(Proc1) > MaxLen Then
  113.         MaxLen := Length(Proc1);        {length of processing message}
  114.      If Length(Done1) > MaxLen Then
  115.         MaxLen := Length(Done1);        {length of finished message}
  116.      If Length(Cancel) > MaxLen Then
  117.         MaxLen := Length(Cancel);       {length of cancel message}
  118.      If Length(Help) > MaxLen Then
  119.         MaxLen := Length(Help);         {length of help message}
  120.      Bounds.Assign(0,0,MaxLen + 4,7);
  121.  
  122.      {call ancestor .Init method}
  123.      TDialog.Init(Bounds, MyTitle);
  124.      MainMessage := Main1;         {assign messages to variables}
  125.      ProcMessage := Proc1;
  126.      DoneMessage := Done1;
  127.      CancelMessage := Cancel;
  128.      HelpMessage   := Help;
  129.      Flags := Flags and not wfClose;   {no close icon on window}
  130.      Options := Options or ofCentered; {center the dialog}
  131.  
  132.      {center main text}
  133.      R := Bounds;               {assign extent of dialog to variable R}
  134.      R.A.X := (R.B.X - Length(MainMessage) - 5) div 2;
  135.      Dec(R.B.X);
  136.      Inc(R.A.Y,2);              {set to second line in dialog}
  137.      R.B.Y := R.A.Y + 1;        {set to one line below R.A.Y}
  138.      Message1 := New(PStaticText, Init(R, MainMessage));
  139.      Insert(Message1);
  140.  
  141.      {insert base value}
  142.      R.A.X := R.A.X + Length(MainMessage) + 1;     {position for values}
  143.      Value := New(PStaticText, Init(R, '   0'));   {start at record 0}
  144.      Insert(Value);
  145.  
  146.      {center processing text and done text}
  147.      R := Bounds;
  148.